# 1.导入request
from urllib import request

url = 'http://httpbin.org/get'
headers = {
    'User-Agent':
        "Mozilla/5.0 (X11; Linux x86_64) "
        "AppleWebKit/537.36 (KHTML, like Gecko) "
        "Chrome/80.0.3987.116 Safari/537.36"
}
# 使用request模块中的Request类创建的对象访问网站
# 2.创建一个Request对象
req = request.Request(url=url,headers=headers)
# 3.发请求获取响应 resp
resp = request.urlopen(req)

# resp = request.urlopen(url)
html = resp.read().decode('utf-8')
print(html)